﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">标题</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" lay-reqtext="标题不能为空" placeholder="请输入标题" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <input type="text" name="description" placeholder="请输入描述" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">等级</label>
            <div class="layui-input-block">
                <input type="number" name="level" lay-verify="required" lay-reqtext="等级不能为空" placeholder="请输入等级" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="number" name="sort" placeholder="请输入排序" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">访问地址</label>
            <div class="layui-input-block">
                <input type="text" name="href" lay-reqtext="访问地址不能为空" placeholder="请输入访问地址" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">父级id</label>
             <div class="layui-input-block">
                <select name="parentId" id="parentSelect">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图标</label>
            <div class="layui-input-block">
                <input type="text" name="icon" placeholder="请输入图标" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">目标</label>
            <div class="layui-input-block">
                <input type="text" name="target" lay-verify="required" lay-reqtext="目标不能为空" placeholder="请输入目标" value="" class="layui-input">
            </div>
        </div>
        @*        <div class="layui-form-item">
            <label class="layui-form-label">部门</label>
            <div class="layui-input-block">
            <select name="departmentId"  id="departmentSelect">
            <option value=""></option>
            </select>
            </div>
            </div>*@

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
    <script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script>
        layui.use(['form'], function () {
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.$;

            //发起异步请求获取部门下拉选数据
            //$.ajax({
            //    url:'/MenuInfo/GetDepartmentOptions',
            //    type:'get',
            //    data:{},
            //    success:function(res){
            //        if(res.isSuccess){
            //            //把备选数据放到下拉选标签元素中
            //            for(var i=0;i<res.data.length;i++){
            //                 //获取下拉选标签元素,并添加option
            //                 $("#departmentSelect").append('<option value="'+ res.data[i].id +'">'+ res.data[i].name +'</option>');
            //            }

            //            //刷新select选择框渲染
            //            form.render('select');
            //        }
            //    }
            //});
              $.ajax({
                    url:'/Menu/GetMenuOptions',
                    type:'get',
                    data:{},
                    success:function(res){
                        if(res.isSuccess){
                            //部门下拉选数据组
                            var menuOptions=res.data;
                            //把备选数据放到父级部门下拉选元素标签中
                            for(var i=0;i<menuOptions.length;i++){
                                //获取下拉选标签元素，并添加option
                              $("#parentSelect").append('<option value="'+ menuOptions[i].id +'">'+ menuOptions[i].name +'</option>');

                            }
                        }
                        form.render('select');
                    }
              });

            //监听提交
            form.on('submit(saveBtn)', function (data) {

                //添加菜单
                $.ajax({
                    url:'/Menu/AddMenu',
                    type:'post',
                    data:data.field,
                    success:function(res){
                        if(res.isSuccess){

                            //重新加载父级表格中的数据
                            //执行搜索重载
                            parent.table.reload('currentTableId', {
                                page: {
                                    curr: 1
                                }
                                , where: {

                                }
                            }, 'data');

                            //关闭添加菜单的页面
                            var iframeIndex = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(iframeIndex);
                        }
                        parent.layer.msg(res.msg);
                    }
                });


                //var index = layer.alert(JSON.stringify(data.field), {
                //    title: '最终的提交信息'
                //}, function () {

                //    // 关闭弹出层
                //    layer.close(index);

                //    //关闭添加菜单的页面
                //    var iframeIndex = parent.layer.getFrameIndex(window.name);
                //    parent.layer.close(iframeIndex);

                //});

                return false;
            });

        });
    </script>
</body>
</html>
